package com.tanhua.server.controller;

import com.tanhua.domain.db.UserInfo;
import com.tanhua.server.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     *第一次完善用户信息
     * 请求链接:POST/user/loginReginfo
     * 请求参数:
     *          Headers:Authorization(token)
     *          Body:userinfo
     * 返回值:
     *          null
     */
    @PostMapping("/loginReginfo")
    public ResponseEntity loginReginfo(@RequestBody UserInfo userInfo){

        return userService.saveUserInfo(userInfo);
    }

    /**
     * 上传用户头像
     * 请求链接:POST/user/loginReginfo/head
     * 请求参数:
     *           Headers:Authorization(token)
     *           Body:headPhoto头像图片 (Spring MVC中 )
     * 返回值:
     *          null
     */
    @PostMapping("/loginReginfo/head")
    public ResponseEntity head(
                               MultipartFile headPhoto) throws IOException {
        return userService.updateUserHead(headPhoto);
    }
}
